<?php

class SearchNotificationLog extends AppModel
{
	var $name = "SearchNotificationLog";
	const ONE_DAY = "1 DAY";
	const TWO_DAY = "2 DAY";
	const ONE_WEEK = "1 WEEK";
	const ONE_MONTH = "1 MONTH";
	function addLog($searchId,$lastSearchedId)
	{
		$data[$this->alias] = array('saved_search_id'=>$searchId,'last_searched_id'=>$lastSearchedId);
		$this->create();
		$this->save($data);
	}
	
	/**
	 * 
	 * @param $searchId
	 * @param $time
	 */
	function allowSearch($searchId,$time = self::ONE_DAY)
	{
		return $this->find('count',array('conditions'=>array("date_sub(NOW(),INTERVAL $time) < created",'saved_search_id'=>$searchId))) == 0;
	}
	/**
	 * 
	 * @param $searchId
	 */
	function getLastSearchedId($searchId)
	{
		return $this->field('last_searched_id',array('saved_search_id'=>$searchId),'id DESC');
	}
}